package com.example.web.mapper;

import com.example.web.pojo.UserT;
import com.example.web.pojo.dto.NewPassword;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserTMapper {

    // 根据用户名查询用户
    @Select("select * from user_t where name = #{name} and is_delete=0")
    UserT selectByName(String name);

    //根据name和password查询用户
    @Select("select * from user_t where name = #{name} and password = #{password} and is_delete=0")
    UserT selectByNameAndPassword(@Param("name") String name, @Param("password") String password);

    //插入用户
    @Insert("insert into user_t(name,password,email,birthday,avatar) values(#{name},#{password},#{email},#{birthday},#{avatar})")
    int insert(UserT userT);

    //根据name删除/注销用户
    @Update("update user_t set is_delete=1 where name=#{name} and is_delete=0")
    int deleteByName(String name);

    //修改密码
    @Update("update user_t set password=#{newPassword} where name=#{name} and password=#{oldPassword} and is_delete=0")
    Integer updatePassword(NewPassword newPassword);
}
